#!/usr/bin/env python
# Copyright(c) 2010 Nuttachat Wisittipanit. All rights reserved.

from mahbo.lib import DB
from minings import Datap
from minings.utility import utility
from minings.factory import datapreprocess

import orange,orngMySQL
from copy import deepcopy


class DataPrePackage(object):
    
    def __init__(self,**kwargs):
        self.fullname       = ''
        self.data           = None  #orange.ExampleTable instance
        self.dataoption     = Datap.Option.whole #0:Whole classes except self.permremovelist,1:fixclass,2:both,3:all duals
        self.keeplist       = []    #list of classes to keep
        self.permremovelist = []    #list to classes to remove
        self.fixedcls       = ''    #Class fixed
        self.matrix         = [ [], [] ] #For special data
        self.pair           = []    #List of pairs for binary classification
        self.run            = None 
        self.Length         = None  #The number of data instances
        self.getPackage     = True
        self.__dict__.update(kwargs)
        self.data           = utility.DatasetTools.finalBrush(self.data)
        if self.getPackage == True:
            self.getDatapackages()
            self.showinf()

    def getDatapackages(self):
        self.GD             = datapreprocess.DATAPREP(self)
        self.datapackages   = self.GD.datapackages
                
    def showinf(self):
        print 'Data Information'
        print 'Data name        : %s' % self.fullname
        print 'Total instances  : %s' % len(self.data)
        print 'Total features   : %s' % len(self.data.domain.attributes)
        print 'Total classes    : %s' % len(self.data.domain.classVar.values)
        print 'Original Class Distribution:'
        for cls,number in zip(self.data.domain.classVar.values,
                              orange.Distribution(self.data.domain.classVar,self.data)):
            print '%-24s: %s' % (cls,int(number))
            

class RESULTS(object):
    
    def __init__(self,**kwargs):
        self.datafact       = None # DataFactory instance
        self.results_svm    = None # RES instance
        self.results_mstat  = None # RES instance
        self.results_som    = None # RES instance
        self.__dict__.update(kwargs)
        
    
        